home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Info-Mac 4
/
Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso
/
Development
/
General
/
Open Prolog
/
External Predicates…
/
Sources
/
countHLE.p
next >
Wrap
Text File
|
1993-04-15
|
3KB
|
116 lines
{$D+} { MacsBug symbols on }
{$R-} { No range checking }
UNIT countHLE;
INTERFACE
USES memtypes, quickdraw, appleEvents, osintf, toolintf, packintf,
prlxdefinitions, prlxLibraries;
PROCEDURE entrypoint(plist: prlxptr);
IMPLEMENTATION
TYPE
eventPtr = ^eventRecord;
longintH = ^longintP;
longintP = ^longint;
PROCEDURE main(plist: prlxptr);
FORWARD;
PROCEDURE entrypoint(plist: prlxptr);
BEGIN
main(plist);
END;
FUNCTION eventCounter(myData: longintH;
theEvent: eventPtr): longint;
BEGIN
IF OSType(theEvent^.message) = kCoreEventClass THEN
myData^^ := myData^^ + 1;
eventCounter := messageNoReply;
{send messageNoReply back to allow the event to be processed normally}
{any other reply will bypass normal event processing and will be the output of the user interface loop}
{a benign reply for an event you use up would be 'messageOK'}
END;
PROCEDURE main;
TYPE
integerHandle = ^integerPtr;
integerPtr = ^integer;
longintHandle = ^longintPtr;
longintPtr = ^longint;
VAR
numberOfMenus, i: integer;
theMenuHandle: menuHandle;
theMenuList: handle;
t: str255;
t1: ptr;
t2: longint;
menuExists: boolean;
BEGIN
WITH plist^ DO
BEGIN
CASE request OF
getPRLXInfo:
BEGIN
data[1] := 1; {number of predicates defined}
data[2] := eventsVersion;
END;
initialisepredicate:
CASE id OF
1:
BEGIN
s := 'system$count$high$level$events'; {name}
data[1] := 1; {arity 1 - count}
data[2] := longint(newHandle(sizeof(longint)));
longintH(data[2])^^ := 0;
callbackrequest := sendEvents; {get prolog to pass raw events
to… }
callbackdata[1] := ord(@eventCounter); {this function (note
its parameter passing
scheme) }
callbackdata[2] := data[2]; {this will be the 'myData' passed
to eventCounter}
callback(entrypoint);
END;
OTHERWISE
errorstr('predicate index out of range at initialise', plist);
END;
callpredicate:
BEGIN
determinate := true;
CASE id OF
1:
BEGIN
successful := returnValue(1, longintH(data[2])^^, plist);
END;
OTHERWISE
errorstr('predicate index out of range at call', plist);
END;
END;
closepredicate:
BEGIN
CASE id OF
1: ;
OTHERWISE
errorstr('predicate index out of range at close', plist);
END;
END;
OTHERWISE errorstr('unknown call to external procedures', plist);
END;
END;
END;
END.